package com.qf.fmall2203.config;

import com.qf.fmall2203.shiro.CustomRealm;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ShiroConfig {

    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition(){

        final DefaultShiroFilterChainDefinition definition = new DefaultShiroFilterChainDefinition();

        // 放行指定的 url
        definition.addPathDefinition("/user/get/**","anon");



        return definition;

    }

    @Bean
    public Realm realm(){
         CustomRealm customRealm = new CustomRealm();

        HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();

        credentialsMatcher.setHashAlgorithmName("md5");

        credentialsMatcher.setHashIterations(1024);

        customRealm.setCredentialsMatcher(credentialsMatcher);

        return customRealm;
    }
}
